package com.my;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.JspFragment;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import java.io.IOException;
import java.io.StringWriter;

/**
 * Created by YJH on 2017/7/6 23:49.
 */
public class PrintUpperTag extends SimpleTagSupport {

    private String time;

    @Override
    public void doTag() throws JspException, IOException {
        //1.得到标签体的内容
        JspFragment bodyContent = getJspBody();
        StringWriter sw = new StringWriter();
        bodyContent.invoke(sw);
        //2.变为大写
        String content = sw.toString();
        content = content.toUpperCase();
        //3.得到out隐含对象变量，循环输出
        int count = 1;
        count = Integer.parseInt(time);
        for (int i = 0; i < count; i++) {
            getJspContext().getOut().println(content);
        }
    }

    public void setTime(String time) {
        this.time = time;
    }
}
